package com.seocoo.worker.user;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.seocoo.worker.R;


public class ShareDialog {
    private AlertDialog dialog;
    private TextView cancelButton;
    private TextView wx_share;
    private TextView wechat_moments_share;

    public ShareDialog(Context context) {
        dialog = new AlertDialog.Builder(context, R.style.CommDialog).create();
        dialog.show();
        Window window = dialog.getWindow();
        window.setContentView(R.layout.share_dialog);
        cancelButton = (TextView) window.findViewById(R.id.share_cancel);
        wechat_moments_share = (TextView) window.findViewById(R.id.wechat_moments_share);
        wx_share = (TextView) window.findViewById(R.id.wx_share);

        // 获取Window的LayoutParams
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        attributes.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
        // 一定要重新设置, 才能生效
        window.setAttributes(attributes);
    }

    public void setCancelButtonOnClickListener(View.OnClickListener Listener) {
        cancelButton.setOnClickListener(Listener);
    }

    public void setWxShareButtonOnClickListener(View.OnClickListener Listener) {
        wx_share.setOnClickListener(Listener);
    }

    public void setWxMomentsShareButtonOnClickListener(View.OnClickListener Listener) {
        wechat_moments_share.setOnClickListener(Listener);
    }

    /**
     * 关闭对话框
     */
    public void dismiss() {
        dialog.dismiss();
    }
}
